﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using System.Collections.ObjectModel;
using Asko.Lib.ViewModels;
using GalaSoft.MvvmLight.Command;

namespace Asko.App.ViewModels
{
    public class AddConnectionViewModel : ViewModelBase
    {
        #region Champs
        private MainViewModel _parent;
        private ObservableCollection<NodeViewModel> _from, _to;
        #endregion

        #region Méthodes
        public AddConnectionViewModel(MainViewModel parent)
        {
            _parent = parent;
            this.From = new ObservableCollection<NodeViewModel>();
            this.To = new ObservableCollection<NodeViewModel>();
            foreach (NodeViewModel nvmTemp in parent.GraphVM.Nodes)
            {
                this.From.Add(nvmTemp);
                this.To.Add(nvmTemp);
            }
            //les commandes
            this.AddCommand = new RelayCommand(() => ExecuteAddCommand(),
                () => this.SelectedFrom != null && this.SelectedTo != null);
        }
        private void ExecuteAddCommand()
        {
            EdgeViewModel evmTemp = new EdgeViewModel();
            evmTemp.Source = this.SelectedFrom;
            evmTemp.Target = this.SelectedTo;
            this.ParentVM.GraphVM.AddEdge(evmTemp);
        }
        #endregion

        #region Propriétés
        public RelayCommand AddCommand
        {
            get;
            private set;
        }
        public ObservableCollection<NodeViewModel> From
        {
            get;
            private set;
        }
        /// <summary>
        /// Retourne le modèle de Vue Parent
        /// </summary>
        public MainViewModel ParentVM
        {
            get { return _parent; }
        }
        public NodeViewModel SelectedFrom
        {
            get;
            set;
        }
        public NodeViewModel SelectedTo
        {
            get;
            set;
        }
        public ObservableCollection<NodeViewModel> To
        {
            get;
            private set;
        }
        #endregion
    }
}
